package com.pay.init;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import com.github.wxisme.bloomfilter.bitset.RedisBitSet;
import com.github.wxisme.bloomfilter.common.BloomFilter;
import com.pay.resource.SpringBeanResource;
import com.pay.service.IMerchantService;
import com.pay.service.IOrderService;
import com.pay.service.IZfbInLogService;
import com.pay.service.IZfbMemberService;
import com.pay.utils.FunctionUtils;

import redis.clients.jedis.Jedis;

@Component
public class InitComponent {

	@Autowired
	private RedisTemplate<String, Object> redisTemplate ; 

	@Autowired
	private IZfbMemberService zfbMemberService ;

	@Autowired
	private IZfbInLogService zfbInLogService ;

	@Autowired
	private RedisConnectionFactory connectionFactory;
	
	@Autowired
	private IOrderService orderService ;
	
	@Autowired
	private IMerchantService merchantService ;
	
	/**
	 * 初始化注入
	 */
	@PostConstruct
	public void init() {
		SpringBeanResource.redisTemplate = redisTemplate ;
		SpringBeanResource.zfbMemberService = zfbMemberService ;
		SpringBeanResource.zfbInLogService = zfbInLogService ;
		SpringBeanResource.connectionFactory = connectionFactory ;
		SpringBeanResource.orderService = orderService ;
		SpringBeanResource.merchantService =  merchantService ;
	}

	/**
	 * 初始化操作
	 */
	@PostConstruct
	public void initPreper() {
		/**
		 * 初始化bloom Filter
		 */
		BloomFilter<String> filter = new BloomFilter<String>(0.0001, 100000);
		Jedis jedis = FunctionUtils.getJedis(connectionFactory);
		filter.bind(new RedisBitSet(jedis, "bloomfilter:zfbkey:zfbname"));
		SpringBeanResource.filter = filter ;
	
		/**
		 * 将全部的支付宝机器人改为离线状态
		 */
		/*List<ZfbMember> zfbMemberList = zfbMemberService.list(null);
		for (ZfbMember zfbMember : zfbMemberList) {
			zfbMember.setStatus(Constant.robto_off_line);
			zfbMemberService.updateById(zfbMember) ;
		}*/
	}
}
